function X = loadLRPatches(Y, PatchPath, Aug, Patch, solver_mode)

if nargin < 3, Aug = []; end

[bFound, ~, MatFile] = myinput.searchDataByParam(PatchPath, 'st-*.mat', 'X-*.mat', Patch, Aug);

%% search for Mat file
if bFound && exist(MatFile, 'file')
    fprintf('\tLoading Low Resolution Image Patches ...\n');
    X = importdata(MatFile);
    if ~ischar(X)
        fprintf('\tDone!\n\n');
        return
    end
    fprintf('\tThe Image Patches are false!\n');
end

%%
% Patch.upsamp = 'I->FSRCNN->VDSR';
splitpattern = '->';
kk = strfind(Patch.flow, splitpattern);
% xflowList = strsplit(Patch.flow, '->');

if length(kk) == 1
    Schedule = sprintf('Generating Low Resolution Image Patches by %s ...', Patch.flow);
    fprintf('\t%s\n', Schedule);
    X = gen_lrimg(Y, Patch);
    fprintf('\tGenerating Image Patches Done! Saving ...\n');
else
    SRMethod = Patch.flow(kk(end)+length(splitpattern) : end);
    Patch.flow = Patch.flow(1 : kk(end)-1);
    X = srdata.loadLRPatches(Y, PatchPath, Aug, Patch);
    
    fprintf('\tSuper-Resolve Low Resolution Image Patches by %s ...\n', SRMethod);
    mycaffe.init(solver_mode, SRMethod);
    hDeploy = srmodel.getDeployFunc(SRMethod, Patch.scale);
    X = hDeploy(X);
    fprintf('\tSuper-Resolve Image Patches Done! Saving ...\n');
end
save(MatFile, '-v7.3', 'X')
fprintf('\tDone!\n\n');

function X = gen_lrimg(Y, Patch)
flowList = strsplit(Patch.flow, '->');
hImgProcess = @(x) srimg.im2lr(x, Patch.scale, flowList{1}, flowList{2});
X = srimg.process(Y, hImgProcess, 9000);
